2000W / 48V LLC Battery-Charger  V1.00
xmc_i2c.h
Go to the documentation of this file.
1 
81 #ifndef XMC_I2C_H
82 #define XMC_I2C_H
83 
84 /*******************************************************************************
85  * HEADER FILES
86  *******************************************************************************/
87 
88 #include "xmc_usic.h"
89 
112 /*******************************************************************************
113  * MACROS
114  *******************************************************************************/
115 
116 #if defined(USIC0)
117 #define XMC_I2C0_CH0 XMC_USIC0_CH0
118 #define XMC_I2C0_CH1 XMC_USIC0_CH1
119 #endif
120 
121 #if defined(USIC1)
122 #define XMC_I2C1_CH0 XMC_USIC1_CH0
123 #define XMC_I2C1_CH1 XMC_USIC1_CH1
124 #endif
125 
126 #if defined(USIC2)
127 #define XMC_I2C2_CH0 XMC_USIC2_CH0
128 #define XMC_I2C2_CH1 XMC_USIC2_CH1
129 #endif
130 
131 #define XMC_I2C_10BIT_ADDR_GROUP (0x7800U)
133 /*******************************************************************************
134  * ENUMS
135  *******************************************************************************/
136 
140 typedef enum XMC_I2C_CH_STATUS
141 {
146 
151 {
170 
177 {
189 
193 typedef enum XMC_I2C_CH_CMD
194 {
198 
202 typedef enum XMC_I2C_CH_EVENT
203 {
221 
225 typedef enum XMC_I2C_CH_INPUT
226 {
228 #if UC_FAMILY == XMC1
229  XMC_I2C_CH_INPUT_SDA1 = 3U,
230  XMC_I2C_CH_INPUT_SDA2 = 5U,
231 #endif
233 #if UC_FAMILY == XMC1
234  XMC_I2C_CH_INPUT_SCL1 = 4U
235 #endif
237 
242 {
249 
250 /*******************************************************************************
251  * DATA STRUCTURES
252  *******************************************************************************/
256 typedef struct XMC_I2C_CH_CONFIG
257 {
258  uint32_t baudrate;
259  uint16_t address;
263 
264 /*******************************************************************************
265  * API PROTOTYPES
266  *******************************************************************************/
267 
268 #ifdef __cplusplus
269 extern "C" {
270 #endif
271 
289 void XMC_I2C_CH_Init(XMC_USIC_CH_t *const channel, const XMC_I2C_CH_CONFIG_t *const config);
290 
306 XMC_I2C_CH_STATUS_t XMC_I2C_CH_SetBaudrate(XMC_USIC_CH_t *const channel, const uint32_t rate);
307 
323 {
325 }
326 
342 
362  const uint8_t service_request)
363 {
365 }
366 
367 
388  const XMC_I2C_CH_INTERRUPT_NODE_POINTER_t interrupt_node,
389  const uint32_t service_request)
390 {
392  (uint32_t)service_request);
393 }
394 
410 __STATIC_INLINE void XMC_I2C_CH_TriggerServiceRequest(XMC_USIC_CH_t *const channel, const uint32_t service_request_line)
411 {
412  XMC_USIC_CH_TriggerServiceRequest(channel, (uint32_t)service_request_line);
413 }
414 
431 __STATIC_INLINE void XMC_I2C_CH_SetInputSource(XMC_USIC_CH_t *const channel, const XMC_I2C_CH_INPUT_t input, const uint8_t source)
432 {
433  channel->DXCR[input] = (uint32_t)(channel->DXCR[input] & (~USIC_CH_DX0CR_INSW_Msk)) | USIC_CH_DX0CR_DSEN_Msk;
434  XMC_USIC_CH_SetInputSource(channel, (XMC_USIC_CH_INPUT_t)input, source);
435 }
436 
455 void XMC_I2C_CH_SetSlaveAddress(XMC_USIC_CH_t *const channel, const uint16_t address);
456 
473 uint16_t XMC_I2C_CH_GetSlaveAddress(const XMC_USIC_CH_t *const channel);
474 
494 void XMC_I2C_CH_MasterStart(XMC_USIC_CH_t *const channel, const uint16_t addr, const XMC_I2C_CH_CMD_t command);
495 
515 void XMC_I2C_CH_MasterRepeatedStart(XMC_USIC_CH_t *const channel, const uint16_t addr, const XMC_I2C_CH_CMD_t command);
516 
530 void XMC_I2C_CH_MasterStop(XMC_USIC_CH_t *const channel);
531 
546 void XMC_I2C_CH_MasterTransmit(XMC_USIC_CH_t *const channel, const uint8_t data);
547 
562 void XMC_I2C_CH_SlaveTransmit(XMC_USIC_CH_t *const channel, const uint8_t data);
563 
577 void XMC_I2C_CH_MasterReceiveAck(XMC_USIC_CH_t *const channel);
578 
592 void XMC_I2C_CH_MasterReceiveNack(XMC_USIC_CH_t *const channel);
593 
607 uint8_t XMC_I2C_CH_GetReceivedData(const XMC_USIC_CH_t *const channel);
608 
620 {
621  return((uint8_t)((channel->RBUF) >> 8U));
622 }
623 
635 void XMC_I2C_CH_EnableEvent(XMC_USIC_CH_t *const channel, uint32_t event);
636 
648 void XMC_I2C_CH_DisableEvent(XMC_USIC_CH_t *const channel, uint32_t event);
649 
661 {
662  return (channel->PSR_IICMode);
663 }
664 
676 __STATIC_INLINE void XMC_I2C_CH_ClearStatusFlag(XMC_USIC_CH_t *const channel, uint32_t flag)
677 {
678  channel->PSCR |= flag;
679 }
680 
700  const uint16_t pdiv,
701  const uint32_t oversampling,
702  const XMC_USIC_CH_INPUT_COMBINATION_MODE_t combination_mode)
703 {
704  XMC_USIC_CH_ConfigExternalInputSignalToBRG(channel,pdiv,oversampling,combination_mode);
705 }
706 
718 {
720 }
721 
733 {
735 }
736 
752 {
754 }
755 
770 {
772 }
773 
789 {
790  channel->PCR_IICMode |= (uint32_t)USIC_CH_PCR_IICMode_MCLK_Msk;
791 }
792 
806 {
807  channel->PCR_IICMode &= (uint32_t)~USIC_CH_PCR_IICMode_MCLK_Msk;
808 }
809 
810 #ifdef __cplusplus
811 }
812 #endif
813 
822 #endif
#define USIC_CH_PCR_IICMode_ARLIEN_Msk
Definition: XMC1400.h:3148
__STATIC_INLINE void XMC_I2C_CH_ConfigExternalInputSignalToBRG(XMC_USIC_CH_t *const channel, const uint16_t pdiv, const uint32_t oversampling, const XMC_USIC_CH_INPUT_COMBINATION_MODE_t combination_mode)
Definition: xmc_i2c.h:699
struct XMC_I2C_CH_CONFIG XMC_I2C_CH_CONFIG_t
I2C_CH configuration structure.
XMC_I2C_CH_INPUT
I2C input stage selection.
Definition: xmc_i2c.h:225
__IO uint32_t PSR_IICMode
Definition: xmc_usic.h:508
__STATIC_INLINE void XMC_I2C_CH_SetInputSource(XMC_USIC_CH_t *const channel, const XMC_I2C_CH_INPUT_t input, const uint8_t source)
Definition: xmc_i2c.h:431
enum XMC_USIC_CH_INPUT XMC_USIC_CH_INPUT_t
XMC_I2C_CH_STATUS
I2C Status.
Definition: xmc_i2c.h:140
XMC_I2C_CH_INTERRUPT_NODE_POINTER
Definition: xmc_i2c.h:241
void XMC_USIC_CH_SetInterruptNodePointer(XMC_USIC_CH_t *const channel, const XMC_USIC_CH_INTERRUPT_NODE_POINTER_t interrupt_node, const uint32_t service_request)
Definition: xmc_usic.c:272
__STATIC_INLINE void XMC_USIC_CH_SetMode(XMC_USIC_CH_t *const channel, const XMC_USIC_CH_OPERATING_MODE_t mode)
Definition: xmc_usic.h:2076
enum XMC_I2C_CH_STATUS XMC_I2C_CH_STATUS_t
I2C Status.
#define USIC_CH_PCR_IICMode_ACKIEN_Msk
Definition: XMC1400.h:3158
I2C_CH configuration structure.
Definition: xmc_i2c.h:256
void XMC_I2C_CH_SetSlaveAddress(XMC_USIC_CH_t *const channel, const uint16_t address)
Definition: xmc_i2c.c:134
#define USIC_CH_PCR_IICMode_SCRIEN_Msk
Definition: XMC1400.h:3140
enum XMC_I2C_CH_INTERRUPT_NODE_POINTER XMC_I2C_CH_INTERRUPT_NODE_POINTER_t
__STATIC_INLINE void XMC_USIC_CH_SetStartTransmisionMode(XMC_USIC_CH_t *const channel, const XMC_USIC_CH_START_TRANSMISION_MODE_t start_transmision_mode)
Definition: xmc_usic.h:1229
__STATIC_INLINE void XMC_I2C_CH_EnableAcknowledgeAddress0(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:717
__STATIC_INLINE void XMC_I2C_CH_TriggerServiceRequest(XMC_USIC_CH_t *const channel, const uint32_t service_request_line)
Definition: xmc_i2c.h:410
#define USIC_CH_PSR_IICMode_NACK_Msk
Definition: XMC1400.h:3318
uint16_t XMC_I2C_CH_GetSlaveAddress(const XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.c:146
uint32_t baudrate
Definition: xmc_i2c.h:258
XMC_I2C_CH_RECEIVER_STATUS_FLAG
I2C receiver status. The received data byte is available at the bit positions RBUF[7:0], whereas the additional information is monitored at the bit positions RBUF[12:8].
Definition: xmc_i2c.h:176
void XMC_I2C_CH_Init(XMC_USIC_CH_t *const channel, const XMC_I2C_CH_CONFIG_t *const config)
Definition: xmc_i2c.c:110
__STATIC_INLINE uint8_t XMC_I2C_CH_GetReceiverStatusFlag(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:619
__STATIC_INLINE void XMC_I2C_CH_Start(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:322
enum XMC_I2C_CH_RECEIVER_STATUS_FLAG XMC_I2C_CH_RECEIVER_STATUS_FLAG_t
I2C receiver status. The received data byte is available at the bit positions RBUF[7:0], whereas the additional information is monitored at the bit positions RBUF[12:8].
void XMC_I2C_CH_MasterStart(XMC_USIC_CH_t *const channel, const uint16_t addr, const XMC_I2C_CH_CMD_t command)
Definition: xmc_i2c.c:192
XMC_I2C_CH_STATUS_t XMC_I2C_CH_Stop(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.c:378
#define USIC_CH_PSR_IICMode_RSCR_Msk
Definition: XMC1400.h:3314
#define USIC_CH_PCR_IICMode_ACK00_Msk
Definition: XMC1400.h:3136
__STATIC_INLINE void XMC_I2C_CH_SelectInterruptNodePointer(XMC_USIC_CH_t *const channel, const XMC_I2C_CH_INTERRUPT_NODE_POINTER_t interrupt_node, const uint32_t service_request)
Definition: xmc_i2c.h:387
#define USIC_CH_PCR_IICMode_MCLK_Msk
Definition: XMC1400.h:3160
uint8_t XMC_I2C_CH_GetReceivedData(const XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.c:360
#define USIC_CH_CCR_BRGIEN_Msk
Definition: XMC1400.h:3202
__STATIC_INLINE void XMC_USIC_CH_TriggerServiceRequest(XMC_USIC_CH_t *const channel, const uint32_t service_request_line)
Definition: xmc_usic.h:1348
#define USIC_CH_PSR_IICMode_AIF_Msk
Definition: XMC1400.h:3338
enum XMC_I2C_CH_EVENT XMC_I2C_CH_EVENT_t
I2C events.
enum XMC_USIC_CH_INTERRUPT_NODE_POINTER XMC_USIC_CH_INTERRUPT_NODE_POINTER_t
#define USIC_CH_PSR_IICMode_RSIF_Msk
Definition: XMC1400.h:3328
__STATIC_INLINE void XMC_I2C_CH_DisableMasterClock(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:805
void XMC_I2C_CH_MasterStop(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.c:250
#define USIC_CH_PSR_IICMode_BRGIF_Msk
Definition: XMC1400.h:3340
#define USIC_CH_PCR_IICMode_PCRIEN_Msk
Definition: XMC1400.h:3144
__STATIC_INLINE void XMC_I2C_CH_EnableMasterClock(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:788
#define USIC_CH_PSR_IICMode_ERR_Msk
Definition: XMC1400.h:3324
#define USIC_CH_PSR_IICMode_TSIF_Msk
Definition: XMC1400.h:3332
#define USIC_CH_DX0CR_DSEN_Msk
Definition: XMC1400.h:2854
XMC_I2C_CH_STATUS_FLAG
I2C status.
Definition: xmc_i2c.h:150
#define USIC_CH_CCR_DLIEN_Msk
Definition: XMC1400.h:3192
__STATIC_INLINE void XMC_I2C_CH_SetInterruptNodePointer(XMC_USIC_CH_t *const channel, const uint8_t service_request)
Definition: xmc_i2c.h:361
enum XMC_I2C_CH_STATUS_FLAG XMC_I2C_CH_STATUS_FLAG_t
I2C status.
#define USIC_CH_CCR_TSIEN_Msk
Definition: XMC1400.h:3194
XMC_I2C_CH_EVENT
I2C events.
Definition: xmc_i2c.h:202
void XMC_I2C_CH_DisableEvent(XMC_USIC_CH_t *const channel, uint32_t event)
Definition: xmc_i2c.c:400
__STATIC_INLINE void XMC_I2C_CH_EnableDataTransmission(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:751
#define USIC_CH_CCR_RSIEN_Msk
Definition: XMC1400.h:3190
#define USIC_CH_PCR_IICMode_NACKIEN_Msk
Definition: XMC1400.h:3146
__I uint32_t RBUF
Definition: xmc_usic.h:516
XMC_I2C_CH_STATUS_t XMC_I2C_CH_SetBaudrate(XMC_USIC_CH_t *const channel, const uint32_t rate)
Definition: xmc_i2c.c:162
#define USIC_CH_CCR_AIEN_Msk
Definition: XMC1400.h:3200
#define USIC_CH_PSR_IICMode_WTDF_Msk
Definition: XMC1400.h:3310
#define USIC_CH_DX0CR_INSW_Msk
Definition: XMC1400.h:2850
#define USIC_CH_CCR_TBIEN_Msk
Definition: XMC1400.h:3196
void XMC_I2C_CH_MasterRepeatedStart(XMC_USIC_CH_t *const channel, const uint16_t addr, const XMC_I2C_CH_CMD_t command)
Definition: xmc_i2c.c:221
XMC_I2C_CH_CMD
I2C commands.
Definition: xmc_i2c.h:193
void XMC_I2C_CH_SlaveTransmit(XMC_USIC_CH_t *const channel, const uint8_t data)
Definition: xmc_i2c.c:294
enum XMC_I2C_CH_INPUT XMC_I2C_CH_INPUT_t
I2C input stage selection.
#define USIC_CH_PSR_IICMode_SLSEL_Msk
Definition: XMC1400.h:3308
#define USIC_CH_PCR_IICMode_RSCRIEN_Msk
Definition: XMC1400.h:3142
#define USIC_CH_PCR_IICMode_SRRIEN_Msk
Definition: XMC1400.h:3150
__STATIC_INLINE uint32_t XMC_I2C_CH_GetStatusFlag(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:660
__IO uint32_t DXCR[6]
Definition: xmc_usic.h:493
#define USIC_CH_PSR_IICMode_RIF_Msk
Definition: XMC1400.h:3336
void XMC_I2C_CH_MasterReceiveNack(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.c:338
enum XMC_I2C_CH_CMD XMC_I2C_CH_CMD_t
I2C commands.
__STATIC_INLINE void XMC_USIC_CH_SetInputSource(XMC_USIC_CH_t *const channel, const XMC_USIC_CH_INPUT_t input, const uint8_t source)
Definition: xmc_usic.h:708
#define USIC_CH_PSR_IICMode_TBIF_Msk
Definition: XMC1400.h:3334
__O uint32_t PSCR
Definition: xmc_usic.h:514
#define USIC_CH_PSR_IICMode_ARL_Msk
Definition: XMC1400.h:3320
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
__IO uint32_t PCR_IICMode
Definition: xmc_usic.h:498
#define USIC_CH_PSR_IICMode_SCR_Msk
Definition: XMC1400.h:3312
void XMC_USIC_CH_ConfigExternalInputSignalToBRG(XMC_USIC_CH_t *const channel, const uint16_t pdiv, const uint32_t oversampling, const XMC_USIC_CH_INPUT_COMBINATION_MODE_t combination_mode)
Definition: xmc_usic.c:180
void XMC_I2C_CH_MasterTransmit(XMC_USIC_CH_t *const channel, const uint8_t data)
Definition: xmc_i2c.c:272
#define USIC_CH_PCR_IICMode_ERRIEN_Msk
Definition: XMC1400.h:3152
#define USIC_CH_CCR_RIEN_Msk
Definition: XMC1400.h:3198
void XMC_I2C_CH_MasterReceiveAck(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.c:316
void XMC_I2C_CH_EnableEvent(XMC_USIC_CH_t *const channel, uint32_t event)
Definition: xmc_i2c.c:394
uint16_t address
Definition: xmc_i2c.h:259
__STATIC_INLINE void XMC_I2C_CH_DisableAcknowledgeAddress0(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:732
#define USIC_CH_PSR_IICMode_PCR_Msk
Definition: XMC1400.h:3316
#define USIC_CH_PSR_IICMode_DLIF_Msk
Definition: XMC1400.h:3330
__STATIC_INLINE void XMC_I2C_CH_DisableDataTransmission(XMC_USIC_CH_t *const channel)
Definition: xmc_i2c.h:769
#define USIC_CH_PSR_IICMode_ACK_Msk
Definition: XMC1400.h:3326
#define USIC_CH_PSR_IICMode_SRR_Msk
Definition: XMC1400.h:3322
enum XMC_USIC_CH_INPUT_COMBINATION_MODE XMC_USIC_CH_INPUT_COMBINATION_MODE_t
__STATIC_INLINE void XMC_I2C_CH_ClearStatusFlag(XMC_USIC_CH_t *const channel, uint32_t flag)
Definition: xmc_i2c.h:676